<script setup lang="ts">
import { addFinanceOrder, listAll } from "@/api/financial/lists";
import PaymentRequest from "./payment-request/payment-request.vue";
const emits = defineEmits(["refresh"]);
const popupRef = ref();
// 打开弹窗
const open = (flow_id: string) => {
    popupRef.value?.open();
    nextTick(async () => {
        dicts.value = await listAll();
        paymentRequestRef.value.setFormData(flow_id);
    });
};
// 请款表单
const paymentRequestRef = ref();
const dicts = ref();
// 提交新增请款单
const handleSumbit = async () => {
    if (!paymentRequestRef.value) return;
    try {
        const params = await paymentRequestRef.value.getFormData();
        await addFinanceOrder(params);
        close();
    } catch (error) {
    }
};
// 关闭弹窗
const close = () => {
    popupRef.value?.close();
    emits("refresh");
    setTimeout(() => {
        if (!paymentRequestRef.value) return;
        paymentRequestRef.value.clearFormData();
    }, 500);
};
defineExpose({ open });
</script>

<template>
    <popup title="新增工程款支付申请单" ref="popupRef" width="1350px" async :footershow="false" :clickModalClose="false">
        <PaymentRequest ref="paymentRequestRef" :disabled="false" :dicts="dicts" isEdit />
        <div class="btns">
            <el-button @click="close"> 取 消 </el-button>
            <el-button @click="handleSumbit" type="primary"> 提 交 </el-button>
        </div>
    </popup>
</template>

<style scoped lang="scss">
.btns {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    height: 50px;
    margin-top: 10px;
}
</style>
